package com.powernode.controller;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.LineCaptcha;
import io.swagger.annotations.Api;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;




@Controller
@Api(tags = "生成验证码【不要测试】")
public class CaptchaController {

    ////以流的形式写出去的验证码
    @RequestMapping("/captcha.do")
    public void captcha(HttpServletResponse response, HttpSession session) throws IOException {
        LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(100, 40, 1, 100);
        String code = lineCaptcha.getCode();
        //将验证码在session中保存一份
        //这个只是获得code值，写入到Sessoion中
        session.setAttribute("code", code);
        //以流的形式写出去的
        lineCaptcha.write(response.getOutputStream());
    }

}
